nat(0).
nat(s(X)):-nat(X).

less-than-or-equal(0, X):-nat(X).
less-than(0,s(X)):-nat(X).

less-than-or-equal(s(X), s(Y)):-less-than-or-equal(X, Y).
less-than(s(X), s(Y)):-less-than(X, Y).

plus(0,X,X):-nat(X).
plus(s(X),Y,s(Z)):-plus(X,Y,Z).

times(0,X,0):-nat(X).
times(s(X),Y,Z):-times(X,Y,W), plus(W,Y,Z).

exp(s(X),0,0):-nat(X).
exp(0,s(X),s(0)):-nat(X).
exp(s(N),X,Y):-exp(N,X,Z), times(Z,X,Y).

fatt(0,s(0)).
fatt(s(N),F):-fatt(N,Z), times(Z,s(N),F).

minimo(N1,N2,N1):-less-than-or-equal(N1, N2).
minimo(N1,N2,N2):-less-than-or-equal(N2, N1).

mod(X,Y,X):-less-than(X, Y).
mod(X,Y,Z):-plus(W,Y,X), mod(W,Y,Z).
